﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FtpCrawler
{
    /// <summary>
    /// 表示Ftp上的文件信息
    /// </summary>
    public class FtpFileInfo
    {

        private int _id;
        private bool _isFile;   // 是否是为件，true为文件，否则为目录
        private string _filename;     // 文件或目录名称
        private string _accessMode;    // unix格式的访问模式
        private int _numLinks;    // 链接数目
        private string _owner;    // 所有者
        private string _group;    // 所属组名
        private DateTime _modifiedTime;   // 修改时间
        private long _size;   // 以字节为单位的文件大小
        private string _path;   // 路径，相对于起始路径

        public bool IsFile
        {
            get { return _isFile; }
            set { _isFile = value; }
        }

        public string Filename
        {
            get { return _filename; }
            set { _filename = value; }
        }

        public string AccessMode
        {
            get { return _accessMode; }
            set { _accessMode = value; }
        }

        public int NumLinks
        {
            get { return _numLinks; }
            set { _numLinks = value; }
        }

        public string Owner
        {
            get { return _owner; }
            set { _owner = value; }
        }

        public string Group
        {
            get { return _group; }
            set { _group = value; }
        }

        public DateTime ModifiedTime
        {
            get { return _modifiedTime; }
            set { _modifiedTime = value; }
        }

        public long Size
        {
            get { return _size; }
            set { _size = value; }
        }

        public string Path
        {
            get { return _path; }
            set { _path = value; }
        }

        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(!this.IsFile ? 'd' : '-');
            sb.Append(this.AccessMode);
            sb.Append(',').Append(this.NumLinks);
            sb.Append(',').Append(this.Owner);
            sb.Append(',').Append(this.Group);
            sb.Append(',').Append(this.Size);
            sb.Append(',').AppendFormat("{0:yyyy-MM-dd HH:mm:ss}", this.ModifiedTime);
            sb.Append(',').Append(this.Path).Append(this.Filename);

            return sb.ToString();
        }
    }

}
